#include "ground_type.h"
#include <util.h>


using namespace std;


static map<unsigned int, GroundType::Index> initColorMap();
static map<string, GroundType::Index> initNameMap();


map<unsigned int, GroundType::Index> GroundType::colorMap = initColorMap();
map<string, GroundType::Index> GroundType::nameMap = initNameMap();


GroundType::Index GroundType::get(unsigned int color)
{
	return colorMap[color];
}


GroundType::Index GroundType::get(string name)
{
	return nameMap[name];
}


static map<unsigned int, GroundType::Index> initColorMap()
{
	map<unsigned int, GroundType::Index> map;

	map[Util_RGB( 64,   0,   0)] = GroundType::OCEAN;
	// Sea Deep - Dark Red Util_RGB(128, 0, 0)
	map[Util_RGB(196,   0,   0)] = GroundType::SEA_SHALLOW;

	//map[] = GroundType::CULTIVATED_LOW;
	//map[] = GroundType::CULTIVATED_MEDIUM;
	//map[] = GroundType::CULTIVATED_HIGH;

	map[Util_RGB(255, 255, 255)] = GroundType::BEACH;
		
	map[Util_RGB(  0, 128, 128)] = GroundType::FERTILITY_LOW;
	map[Util_RGB( 96, 160,  64)] = GroundType::FERTILITY_MEDIUM;
	map[Util_RGB(101, 124,   0)] = GroundType::FERTILITY_HIGH;

	map[Util_RGB(  0,  64,   0)] = GroundType::FOREST_DENSE;
	map[Util_RGB(  0, 128,   0)] = GroundType::FOREST_SPARSE;
	map[Util_RGB(128, 128,  64)] = GroundType::HILLS;
	map[Util_RGB(196, 128, 128)] = GroundType::MOUNTAINS_HIGH;
	map[Util_RGB( 98,  65,  65)] = GroundType::MOUNTAINS_LOW;
	map[Util_RGB(  0, 255, 128)] = GroundType::SWAMP;
	map[Util_RGB(  0,   0,   0)] = GroundType::FERTILITY_LOW;

	//map[]					= GroundType::SCORCHED;

	map[Util_RGB( 64,  64,  64)] = GroundType::IMPASSABLE_LAND;
	// impassable_sea		impassable_sea.tga

	return map;
}


static map<string, GroundType::Index> initNameMap()
{
	map<string, GroundType::Index> map;

	map["beach"]				= GroundType::BEACH;

	map["cultivated_low"]		= GroundType::CULTIVATED_LOW;
	map["cultivated_medium"]	= GroundType::CULTIVATED_MEDIUM;
	map["cultivated_high"]		= GroundType::CULTIVATED_HIGH;
		
	map["fertility_low"]		= GroundType::FERTILITY_LOW;
	map["fertility_medium"]		= GroundType::FERTILITY_MEDIUM;
	map["fertility_high"]		= GroundType::FERTILITY_HIGH;

	map["forest_dense"]			= GroundType::FOREST_DENSE;
	map["forest_sparse"]		= GroundType::FOREST_SPARSE;
	map["hills"]				= GroundType::HILLS;
	map["mountains_high"]		= GroundType::MOUNTAINS_HIGH;
	map["mountains_low"]		= GroundType::MOUNTAINS_LOW;
	map["swamp"]				= GroundType::SWAMP;
	map["wilderness"]			= GroundType::WILDERNESS;

	map["scorched"]				= GroundType::SCORCHED;

	map["impassable_land"]		= GroundType::IMPASSABLE_LAND;
	
	return map;
}
